using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CodeStory.WebControls
{
	public abstract class TreeGridColumn : IStateManager
	{
		private TreeGrid treeGrid;
		private TableItemStyle headerStyle;
		private TableItemStyle itemStyle;
		private bool isTrackingViewState = false;
		private StateBag viewState;


		protected StateBag ViewState {
			get {
				if (viewState == null) {
					viewState = new StateBag();
				}
				return viewState;
			}
		}

		[PersistenceMode(PersistenceMode.InnerProperty)]
		[DefaultValue((string)null)]
		[Category("Styles")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		public virtual TableItemStyle HeaderStyle {
			get {
				if (this.headerStyle == null) {
					this.headerStyle = new TableItemStyle();
					if (this.IsTrackingViewState) {
						((IStateManager)this.headerStyle).TrackViewState();
					}
				}
				return this.headerStyle;
			}
		}
		[DefaultValue((string)null)]
		[PersistenceMode(PersistenceMode.InnerProperty)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		[Category("Styles")]
		public virtual TableItemStyle ItemStyle {
			get {
				if (this.itemStyle == null) {
					this.itemStyle = new TableItemStyle();
					if (this.IsTrackingViewState) {
						((IStateManager)this.itemStyle).TrackViewState();
					}
				}
				return this.itemStyle;
			}
		}
		[DefaultValue("")]
		[Category("Appearance")]
		public virtual string HeaderText {
			get {
				object obj2 = this.ViewState["HeaderText"];
				if (obj2 != null) {
					return (string)obj2;
				}
				return string.Empty;
			}
			set {
				this.ViewState["HeaderText"] = value;
				//this.OnColumnChanged();
			}
		}
		public TreeGrid TreeGrid {
			get { return treeGrid; }
		}

		public void LoadViewState(object savedState) {
			if (savedState != null) {
				object[] objArray = (object[])savedState;
				if (objArray[0] != null) {
					((IStateManager)this.ViewState).LoadViewState(objArray[0]);
				}
				if (objArray[1] != null) {
					((IStateManager)this.ItemStyle).LoadViewState(objArray[1]);
				}
				if (objArray[2] != null) {
					((IStateManager)this.HeaderStyle).LoadViewState(objArray[2]);
				}
			}
		}

		public object SaveViewState() {
			object obj1 = ((IStateManager)this.ViewState).SaveViewState();
			object obj2 = (this.itemStyle != null) ? ((IStateManager)this.itemStyle).SaveViewState() : null;
			object obj3 = (this.headerStyle != null) ? ((IStateManager)this.headerStyle).SaveViewState() : null;
			if ((obj1 == null && obj2 == null) && (obj3 == null)) {
				return null;
			}
			return new object[] {obj1, obj2, obj3};
		}

		public void TrackViewState() {
			isTrackingViewState = true;
			((IStateManager)this.ViewState).TrackViewState();
			if (this.itemStyle != null) {
				((IStateManager)this.itemStyle).TrackViewState();
			}
			if (this.headerStyle != null) {
				((IStateManager)this.headerStyle).TrackViewState();
			}
		}

		public bool IsTrackingViewState {
			get { return this.isTrackingViewState; }
		}

		internal void SetTreeGrid(TreeGrid treeGrid) {
			this.treeGrid = treeGrid;
		}

		internal void SetDirty() {
			ViewState.SetDirty(true);
		}

		public virtual void BuildIn(TableCell cell,bool databound,IDataItemContainer dataItemContainer) {
			
		}
	}
}